﻿using System;
using System.Collections.Generic;
using System.Linq;
using Simple.Data;
using Model.Course;

namespace Model.Communication
{
    public class Forum
    {
        protected Int32 id;
        protected Int32 courseId;

        protected Forum()
        {
        }

        protected Forum(int id, int courseId)
        {
            this.id = id;
            this.courseId = courseId;
        }

        public static Forum create(Course.Course course)
        {
            var db = Database.Open();
            if (db.Forum.GetCountByCourse(course.getId()) > 0)
                return null;

            var forum = db.Forum.Insert(Course: course.getId());

            return new Forum(forum.id, forum.course);
        }

        public static Forum get(Course.Course course)
        {
            var forum = Database.Open().Forum.FindByCourse(course.getId());

            if (forum == null)
                return null;

            return new Forum(forum.id, forum.course);
        }

        public int getId()
        {
            return id;
        }

        public int getCourseId()
        {
            return courseId;
        }
    }
}